home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / incl / LEDA / polygon.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  2.3 KB  |  108 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  polygon.h
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #ifndef LEDA_POLYGON_H
  16. #define LEDA_POLYGON_H
  17.  
  18. #include <LEDA/point.h>
  19. #include <LEDA/segment.h>
  20. #include <LEDA/line.h>
  21.  
  22. //------------------------------------------------------------------------------
  23. // polygons
  24. //------------------------------------------------------------------------------
  25.  
  26.  
  27.  
  28. class polygon_rep : public handle_rep {
  29.  
  30. friend class polygon;
  31.  
  32.   list<segment> seg_list;
  33.  
  34. public:
  35.  
  36.   polygon_rep() { }
  37.   polygon_rep(const list<segment>& L) { seg_list = L; }
  38.  
  39.  ~polygon_rep() {}
  40.    
  41.   LEDA_MEMORY(polygon_rep)
  42.    
  43. };
  44.  
  45.  
  46. class list_polygon_;
  47.  
  48.  
  49. class polygon   : public handle_base 
  50. {
  51.  
  52. polygon_rep* ptr() const { return (polygon_rep*)PTR; }
  53.  
  54. bool check();
  55.  
  56. public:
  57.  
  58.  polygon();
  59.  polygon(const list<point>&, bool=true);
  60.  
  61.  polygon(const polygon& P) : handle_base(P) {}
  62.  
  63. ~polygon()                { clear(); }
  64.  
  65. polygon& operator=(const polygon& P) { handle_base::operator=(P); return *this;}
  66.  
  67.  
  68. list<point>   vertices() const;  
  69. list<segment> segments() const { return ptr()->seg_list; }
  70.  
  71. bool          inside  (const point& p) const;  
  72. bool          outside (const point& p) const; 
  73.  
  74. list<point>   intersection(const segment& s) const;
  75. list<point>   intersection(const line& l) const;  
  76. list_polygon_ intersection(const polygon& P) const;
  77.  
  78. polygon       translate(double, double) const;
  79. polygon       translate(const vector&) const;
  80.  
  81. polygon       rotate(const point&, double) const;
  82. polygon       rotate(double) const;
  83.  
  84. int         size()   const  { return ptr()->seg_list.size(); }
  85. bool        empty()  const  { return ptr()->seg_list.empty(); }
  86.  
  87. polygon operator+(const vector& v) const { return translate(v); }
  88.  
  89. friend ostream& operator<<(ostream& out, const polygon& p);
  90. friend istream& operator>>(istream& in,  polygon& p);
  91.  
  92. };
  93.  
  94. inline void Print(const polygon& P, ostream& out) { out << P; } 
  95. inline void Read(polygon& P, istream& in)         { in  >> P; }
  96.  
  97. LEDA_HANDLE_TYPE(polygon)
  98.  
  99.  
  100. struct list_polygon_: public list<polygon>
  101. {
  102.   list_polygon_(const list<polygon>& L) : list<polygon>(L) {}
  103. };
  104.  
  105.  
  106. #endif 
  107.